package com.sneakxy.mybatis.commons.repository.query.domain;

import java.io.Serializable;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
 * @author 潜行的青衣
 */
public class Condition implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8308869290808479306L;

	private String operator;
	
	private Criterion criterion;
	
	public Condition(String operator, Criterion criterion) {
		this.operator = operator;
		this.criterion = criterion;
	}

	public String getOperator() {
		return operator;
	}

	public Criterion getCriterion() {
		return criterion;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder()
				.append(this.operator)
				.append(this.criterion).toHashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if(obj == null) {
			return false;
		}
		if(!(obj instanceof Condition)) {
			return false;
		}
		Condition cond = (Condition) obj;
		return new EqualsBuilder()
				.append(this.operator, cond.operator)
				.append(this.criterion, cond.criterion).isEquals();
	}
	
}
